<?php

class Goal extends CActiveRecord
{
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	public function tableName()
	{
		return 'goal';
	}

	public function rules()
	{
		return array(
			array('profileId, title', 'required'),
			array('profileId', 'numerical', 'integerOnly'=>true),
			array('title', 'length', 'max'=>255),
			array('profileId, id, title', 'safe', 'on'=>'search'),
		);
	}

	public function relations()
	{
		return array(
			'profile'=>array(self::BELONGS_TO, 'Profile', 'profileId'),
		);
	}

	public function attributeLabels()
	{
		return array(
			'profileId'=>'Айди профиля',
			'id'=>'ID',
			'title'=>'Цель',
		);
	}

	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('profileId',$this->profileId);
		$criteria->compare('id',$this->id);
		$criteria->compare('title',$this->title,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}